﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Data.OleDb;
using Maticsoft.DBUtility;
using System.Text;
using System.Data;
using Common;

namespace Habito.Admini
{
	public partial class ContactUs : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(Ticket.UserName) || Session["username"] == null)
			{
				Response.Redirect("Login.aspx");
			}
			string content = GetContent();
			ViewState["content"] = content;
		}
		protected override void OnInit(EventArgs e)
		{
			if (Request.QueryString["Save"] == "1")
			{
				string content = Request.Params["description"];
				string sql = "update contactus set content = @content";
				OleDbParameter[] parameters = {
					new OleDbParameter("@content", OleDbType.VarChar,100000)};
				parameters[0].Value = content;
				object obj = DataOperate.ExecuteNonQuery(PubConstant.ConnectionString, sql, parameters);
				if (obj == null)
				{
					Response.Write("0");
					Response.End();
				}
				else
				{
					int success = Convert.ToInt32(obj.ToString());
					bool result = success > 0;
					Response.Write("1");
					Response.End();
				}
			}
			base.OnInit(e);
		}
		private string GetContent()
		{

			StringBuilder strSql = new StringBuilder();
			strSql.Append("select ID,content from contactus ");
			strSql.Append(" where ID=@ID");
			OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
			};
			parameters[0].Value = 1;

			Ajax.Model.ProductClass model = new Ajax.Model.ProductClass();
			DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
			if (ds.Tables[0].Rows.Count > 0)
			{
				return ds.Tables[0].Rows[0]["Content"].ToString();
			}
			else
			{
				return "";
			}
		}
	}
}